how to solve Ugly numbers problem